<template>
  <div class="prodeCtionEdit" @click.stop="aotuTab=false">
    <div class="headBtn">
      <jc-button
        :btn-arr="['option', 'reload', 'pass', 'sub', 'save', !list.length && 'check', 'push', 'settle', 'list']"
        :disab-arr="[isDisabled && 'save', 'close', 'cancel', 'toExcel', 'com2', 'using', 'freeze']"
        :fbillno="production.fbillNo"
        :list="'/ingredientList'"
        @save="prdbomDetails()"
        @refresh="getSCLLinfo"
        @submit="prdbomDetails(1)"
        @noSubmit="submit(2)"
        @audit="audit(1)"
        @noAudit="audit(2)"
        @pushDown="pushDown"
        @handleCom1="printing1"
        @settle="settle"
        @check="check('up')"
        @check1="check('down')"
      />
      <!--      <el-button style="margin-left: 10px;" type="primary" size="mini" @click="handleNextCheck">-->
      <!--        下查-->
      <!--      </el-button>-->
    </div>
    <el-tabs v-model="activeName" @tab-click="handleOther">
      <el-tab-pane :label="$t('market.info')" name="first">
        <el-form ref="purchaseRef" :model="production" label-width="100px">
          <el-form-item :label="$t('market.state')">
            <el-tag :type="production.stateColor">
              {{ production.fdocumentStatus }}
            </el-tag>
          </el-form-item>
          <el-form-item :label="$t('market.pbomBillNo')" label-width="6vw">
            <el-input v-model.trim="production.fbillNo" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.productmolde')">
            <el-input v-model.trim="production.fmodel" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.productNo')">
            <el-input v-model.trim="production.fnumber" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.productName')">
            <el-input v-model.trim="production.fmaterialName" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.proSpecifica')">
            <el-input
              v-model.trim="production.fspecificaTion"
              size="mini"
              disabled
            />
          </el-form-item>
          <el-form-item :label="$t('market.workshop')">
            <el-input
              v-model.trim="production.fworkshop"
              size="mini"
              disabled
            />
          </el-form-item>
          <el-form-item :label="$t('market.funit')">
            <el-input v-model.trim="production.unitName" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.fqty')">
            <el-input v-model.trim="production.fqty" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.proOrderNo')" label-width="6vw">
            <el-input
              v-model.trim="production.fmobillNo"
              size="mini"
              disabled
            />
          </el-form-item>
          <!--          <el-form-item label="生产订单状态" label-width="6vw">-->
          <!--            <el-select-->
          <!--              v-model="production.fstatusId"-->
          <!--              size="mini"-->
          <!--              @change="tabStus"-->
          <!--            >-->
          <!--              <el-option v-for="item in statusData" :key="item.fvalue" :label="item.fname" :value="item.fvalue" />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->
          <el-form-item :label="$t('market.createtime')">
            <el-input
              v-model.trim="production.fcreateDate"
              disabled
              size="mini"
            />
          </el-form-item>
          <el-form-item :label="$t('market.jcfprice')">
            <el-input-number
              v-model="production.fJcFprice"
              :disabled="isDisabled"
              controls-position="right"
              size="mini"
            />
          </el-form-item>
          <el-form-item :label="$t('market.purinstockqty')">
            <el-input
              v-model="production.fcompleteqty"
              disabled
              size="mini"
            />
          </el-form-item>
          <el-form-item :label="$t('market.paezText1')">
            <el-input
              v-model="production.salkhddh"
              disabled
              size="mini"
            />
          </el-form-item>
          <!--          <el-form-item label="生产组织">-->
          <!--            <el-input v-model.trim="production.fprdorg" disabled />-->
          <!--          </el-form-item>-->
          <el-form-item :label="$t('market.productDesc')" class="miaoshu">
            <el-input
              v-model.trim="production.fdescripTion"
              size="mini"
              disabled
            />
          </el-form-item>
        </el-form>
        <div style="margin-top: 10px;">
          <div style="margin-bottom: 5px">
            <el-button size="mini" @click="newLine">{{ $t('btn.newHang') }}<!--新增行--></el-button>
            <el-button size="mini" @click="delHang">{{ $t('btn.delHang') }}<!--删除行--></el-button>
          </div>
          <jc-table
            ref="multipleTable"
            :table-data="tableData"
            :table-header="tableHeard"
            :table-height="tableHeight"
            table-selection
            :get-summaries="getSummaries"
            show-summary
            @selectionChange="selectData"
          >
            <template v-slot:tagSlot="col">
              <el-input
                v-model.trim="col.scope.row.fnumber"
                size="mini"
                :disabled="isDisabled || col.scope.row.fneedQty > 0"
                @input="getAtuo(col.scope.$index, col.scope.row.fnumber)"
              >
                <i
                  slot="prefix"
                  class="iconfont icon-jin-rud-ao-bo"
                  @click="sonJumpMateriel(col.scope.row.fnumber)"
                />
                <i
                  slot="suffix"
                  class="el-input__icon el-icon-search"
                  @click="materia(col.scope.$index)"
                />
              </el-input>
              <div v-if="aotuTab && indexSelf === col.scope.$index" :class="indexSelf<7 ? 'tabPosit': 'tabPosit1'">
                <number-code :fnumber="fnumber" @material="materialData" />
              </div>
            </template>
            <!--发料方式-->
            <template v-slot:orderSlot="col">
              <el-select
                v-if="!isDisabled"
                v-model="col.scope.row.fissueTypeId"
                :disabled="isDisabled || col.scope.row.fneedQty > 0"
                size="mini"
              >
                <el-option v-for="item in issueTypeData" :key="item.fid" :label="item.fname" :value="item.fid" />
              </el-select>
              <span v-else>
                <el-tag v-if="col.scope.row.fissueTypeId===42" type="success">{{ col.scope.row.fissueType }}</el-tag>
                <el-tag v-else type="primary">{{ col.scope.row.fissueType }}</el-tag>
              </span>
            </template>
            <!--用量-->
            <template v-slot:btnState="col"><!--|| col.scope.row.fneedQty > 0-->
              <el-input-number
                v-model="col.scope.row.fnumeraTor"
                :disabled="isDisabled || col.scope.row.fmustQty - col.scope.row.fneedQty <= 0"
                :min="0"
                size="mini"
                @change="handleChange(col.scope.$index)"
              />
            </template>
            <!--已领数量-->
            <template v-slot:billSlot="col">
              <span
                v-if="col.scope.row.fneedQty === 0"
                @click="pushDeta(col.scope.row.fentryId)"
              >0</span>
              <span
                v-else-if="col.scope.row.fneedQty !== col.scope.row.fmustQty"
                style="color: #e6a23c;"
                @click="pushDeta(col.scope.row.fentryId)"
              >
                {{ col.scope.row.fneedQty }}
              </span>
              <span
                v-else-if="col.scope.row.fneedQty === col.scope.row.fmustQty"
                style="color: #67c23a;"
                @click="pushDeta(col.scope.row.fentryId)"
              >
                {{ col.scope.row.fneedQty }}
              </span>
            </template>
            <!-- 仓库-->
            <template v-slot:operaSlot="col">
              <el-input
                v-if="!isDisabled"
                v-model="col.scope.row.stockName"
                size="mini"
                :disabled="isDisabled || col.scope.row.fneedQty > 0"
              >
                <i
                  slot="suffix"
                  class="el-input__icon el-icon-search"
                  @click="handleWarehouse(col.scope.$index)"
                />
              </el-input>
              <span v-else>{{ col.scope.row.stockName }}</span>
            </template>
            <template v-slot:btnSlot="col">
              <el-select v-model="col.scope.row.isSaled" :disabled="isDisabled || col.scope.row.fneedQty > 0">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </template>
            <template v-slot:text1Slot="col">
              <el-checkbox v-model="col.scope.row.fissue" :disabled="isDisabled || col.scope.row.fneedQty > 0" />
            </template><!--客户订单号-->
            <template v-slot:text2Slot="col">
              <el-input v-model="col.scope.row.fpaezText" :disabled="isDisabled|| col.scope.row.fneedQty > 0" />
            </template><!--要货日期-->
            <template v-slot:text3Slot="col">
              <el-date-picker
                v-model.trim="col.scope.row.fneeddate"
                type="date"
                value-format="yyyy-MM-dd"
                size="mini"
                :disabled="isDisabled || col.scope.row.fneedQty > 0"
                style="width: 163px"
              />
            </template>
          </jc-table>
        </div>
      </el-tab-pane>
      <el-tab-pane :label="$t('market.other')" name="log">
        <jc-marker
          ref="log"
          :fnumber="production.fbillNo"
          other-height="68vh"
          :other-url-object="otherUrlObject"
        />
      </el-tab-pane>
    </el-tabs>
    <el-dialog
      v-dialogDrag
      :title="$t('market.checkBill')"
      model
      :visible.sync="isdanjuDialog"
      :close-on-click-modal="false"
      width="600px"
      top="5vh"
      center
    >
      <div style="text-align: center;height: 100px;line-height: 100px">
        <el-radio-group v-model="orderLX" @change="handleOrder">
          <el-radio v-for="item in receipts" :key="item" :label="item">
            {{ item }}
          </el-radio>
        </el-radio-group>
      </div>
      <hr>
      <div v-if="orderBool" style="text-align: center;">
        {{ $t('market.rule') }}
        <el-input v-model="convert" size="mini" disabled style="width: 178px;margin-bottom: 5px;" />
        <br>
        {{ $t('market.billType') }}
        <el-select
          v-model.trim="fbillTypeId"
          size="mini"
          filterable
        >
          <el-option
            v-for="(item, index) in billTypeData"
            :key="index"
            :label="item.fname"
            :value="item.fid"
          />
        </el-select>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isdanjuDialog = false">{{ $t('btn.cancel') }}</el-button>
        <el-button size="mini" type="primary" @click="pushDownOrder()">
          {{ $t('btn.confirm') }}
        </el-button>
      </span>
    </el-dialog>
    <!--    物料弹窗-->
    <material v-if="isMateria" @material="materialData" />
    <!--    反查弹窗-->
    <el-dialog
      v-dialogDrag
      :title="$t('market.pegging')"
      model
      :visible.sync="isNextCheck"
      :close-on-click-modal="false"
      width="600px"
      top="5vh"
    >
      <jc-table :table-data="nextCheckData" :table-header="nextCheckHeader">
        <el-table-column :label="$t('market.billNo')" prop="fbillNo" align="center">
          <template slot-scope="scope">
            <el-link type="primary" @click="jumpPage(scope.row)">{{ scope.row.fbillNo }}</el-link>
          </template>
        </el-table-column>
        <template v-slot:btnSlot="col">
          <el-tag
            :type="col.scope.row.stateColor"
          >
            {{ col.scope.row.fdocumentstatus }}
          </el-tag>
        </template>
      </jc-table>
    </el-dialog>
    <!-- 仓库 -->
    <selectCK
      v-if="seleceVisiblit"
      :msg="msgCK"
      :fmaterial-id="stockFnumber"
      @client="selectCK"
    />
    <!-- 下推明细 -->
    <pushDetail
      v-if="pushVisiblit"
      :fid="pushEntryId"
      type="1"
      @client="pushVisiblit=false"
    />
    <upDown v-if="upDownVis" :msg="cha" :fentryid="fentryData" @client="upDownVis=false" />
  </div>
</template>

<script>
import {
  queryPrdbomDetails,
  updatePrdPpbom,
  queryPpbomPushList,
  auditPrdPpboms,
  unauditPrdPpboms,
  submitPrdPpboms,
  unsubmitPrdPpboms,
  updateMoStatus,
  pushToPickmtrl, pushToPrdReturnmtrl, pushToPrdInstock,
  pushToPrdUninstock, finishPrdPpboms, pushToSupplement, insertProcess, pushMoCheck, insertOutsource
} from '@/api/production/productionList'
import { toMxAmina, toMxBmina } from '@/components/ToMxamineState'
import { maxDecimal } from '@/utils/number'
import pushDetail from '@/views/production/collect/components/pushDetail'
import autocomplete from '@/views/market/marketManage/createMarkerOrder/components/autocomplete'
import operability from '@/mixin/Operability'
import { queryViewItem } from '@/api/marketManage/marketOrder'
import jcMarker from '@/components/marker'
import jcButton from '@/components/Button'
import jumpMateriel from '@/components/JumpMateriel'
import { insertMoparts } from '@/api/production/semifinish'

export default {
  name: 'ProductionEdit',
  components: {
    upDown: () => import('@/components/upDown'),
    material: () => import('@/views/market/marketManage/createMarkerOrder/components/material'),
    selectCK: () => import('@/views/production/collect/components/seleceCK'),
    numberCode: () => import('@/components/NumberCode'),
    jcMarker,
    jcButton,
    pushDetail
  },
  mixins: [autocomplete, operability, jumpMateriel],
  props: {
    msg: {
      type: String,
      default: ''
    },
    fseq: {
      // 行号
      type: [Number, String],
      default: 0 || ''
    },
    list: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  data() {
    return {
      fentryData: [],
      upDownVis: false,
      cha: '',
      msgCK: 2, // 转入仓库
      targerName: 'productionEdit',
      aotuTab: false,
      fnumber: '',
      activeName: 'first',
      production: {},
      isDisabled: false,
      stockFnumber: '',
      seleceVisiblit: false, // 仓库
      pushVisiblit: false,
      pushEntryId: 0,
      indexSelf: 0, // 弹窗下标
      isMateria: false, // 物料弹窗
      isdanjuDialog: false, // 单据
      isNextCheck: false, // 下查
      orderLX: this.$t('menu.proPickLian'),
      // '生产领料单''生产退料单''生产入库单''生产退库单' '生产补料单' '生产流程单'
      receipts: [this.$t('menu.proPickLian'), this.$t('menu.proSupplTong'), this.$t('menu.proStirageOrder'), this.$t('menu.proTuiStockDetail'),
        this.$t('menu.supplementary'), this.$t('menu.workFlowOrder'), this.$t('menu.qualityOrder'),
        this.$t('menu.outProcessOrder'), this.$t('menu.semifinishDetail')], // 生产
      fbillTypeId: 184,
      convert: this.$t('market.scylzlc'), // '生产用料单至生产流程单'
      billTypeData: [],
      orderBool: false,
      tableHeight: '65vh',
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 0 }
      ],
      tableData: [],
      tableHeard: [
        { label: this.$t('market.fseq'), prop: 'fseq', width: '50' },
        // { label: this.$t('market.proOrderSeq'), prop: 'fmoentrySeq', width: '80' },
        {
          label: this.$t('market.subitemNum'),
          type: 'tag',
          prop: 'fnumber',
          width: '170px'
        },
        { label: this.$t('shop.fname2'), prop: 'fname', width: '100' },
        // { label: this.$t('market.fmodel'), prop: 'fmodel', width: '100' },
        { label: this.$t('shop.fspecificaTion'), prop: 'fspecificaTion', width: '120' },
        {
          label: this.$t('market.issueType'),
          type: 'order',
          prop: 'fissueType',
          width: '100px'
        },
        { label: this.$t('market.sengMater'), type: 'text1', width: '80' },
        { label: this.$t('market.funit'), prop: 'funitName', width: '80' },
        { label: this.$t('market.mustqty'), prop: 'fmustQty', width: '80' },
        { label: this.$t('market.alreadyQty'), type: 'bill', prop: 'fneedQty', width: '80' },
        { label: this.$t('market.unreceQty'), prop: 'fstdQty', width: '80' },
        { label: this.$t('market.dosage'), type: 'state', prop: 'fnumeraTor', width: '90' },
        { label: this.$t('market.stock2'), type: 'operate', prop: 'stockName', width: '120' },
        { label: this.$t('market.stockQty'), prop: 'stockQty', width: '80' },
        { label: this.$t('market.isSaled'), type: 'btn', prop: 'isSaled', width: '80' },
        { label: this.$t('market.paezText1'), prop: 'fpaezText', type: 'text2', width: '120' },
        // { label: this.$t('market.deliveryDate'), prop: 'fneeddate', type: 'text3', width: '120' },
        { label: this.$t('market.fdescripTion'), prop: 'fdescripTion', minWidth: '200px' }
        // { label: '入库组织', prop: 'fstockorg' },
        // { label: '货主', prop: 'fowner' }
      ],
      nextCheckData: [],
      nextCheckHeader: [
        { label: this.$t('market.billTypeName'), prop: 'typeName' },
        { label: this.$t('market.documentstatus'), type: 'btn', prop: 'fdocumentstatus' },
        { label: this.$t('market.createDate'), prop: 'createTime' }
      ],
      issueTypeData: [], // 发料方式
      statusData: [], // 生产订单状态
      delArr: [],
      otherUrlObject: {}
    }
  },
  watch: {
    msg: {
      handler(val) {
        if (val) {
          this.getSCLLinfo()
        }
      },
      immediate: true
    }
  },
  created() {
    if (this.$route.params.id) {
      this.getSCLLinfo()
    }
    this.issueType()
    this.statusPro()
    this.tableHeight = window.innerWidth > 1440 ? 'calc(100vh - 320px)' : '65vh'
  },
  methods: {
    handleOrder(val) {
      if (val === this.$t('menu.qualityOrder')) {
        this.convert = this.$t('market.scbjy') // '生产订单至品质检验单'
        this.fbillTypeId = 184
        this.orderBool = true
        this.purpoorder1('SX_CHECKOUT')
      } else if (val === this.$t('menu.workFlowOrder')) {
        this.convert = this.$t('market.sczlc') // '生产订单至生产流程单'
        this.fbillTypeId = 245
        this.orderBool = true
        this.purpoorder1('SX_PROCESS')
      } else if (val === this.$t('menu.outProcessOrder')) {
        this.convert = this.$t('market.sczgx') // '生产订单至外包工序单'
        this.fbillTypeId = 1317
        this.orderBool = true
        this.purpoorder1('SX_OUTSOURCE')
      } else if (val === this.$t('menu.semifinishDetail')) {
        this.convert = this.$t('market.scylzbcp') // '生产用料单至半成品入库'
        this.fbillTypeId = 1511
        this.orderBool = true
        this.purpoorder1('SX_MOPARTS')
      } else {
        this.orderBool = false
      }
    },
    // 生产流程单
    async purpoorder1(ev) {
      const { data: RES } = await queryViewItem({ viewName: ev })
      this.billTypeData = RES.list
    },
    // 下推明细
    pushDeta(id) {
      this.pushVisiblit = true
      this.pushEntryId = id
    },
    // 发料方式
    async issueType() {
      const { data: RES } = await queryViewItem({ viewName: 'SX_V_UNIT_ISSUETYPE' })
      this.issueTypeData = RES.list
    }, // 委外订单状态
    async statusPro() {
      const { data: RES } = await queryViewItem({ viewName: 'SX_V_MOSTATUS' })
      this.statusData = RES.list
    },
    // 输入物料编码
    getAtuo(index, fnumber) {
      this.indexSelf = index
      this.aotuTab = true
      var vm = this
      clearTimeout(vm.timer) // 清除未执行的代码，重置回初始化状态
      vm.timer = setTimeout(() => {
        this.fnumber = fnumber
      }, 600)
    },
    // 获取下查
    async handleNextCheck() {
      this.isNextCheck = true
      const { data: res, code, message } = await queryPpbomPushList({
        ppbomNo: this.production.fbillNo
      })
      if (code !== 0) {
        this.$confirm(message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        })
        return
      }
      this.nextCheckData = res.map(item => {
        return toMxBmina(item)
      })
    },
    // 根据单据编号跳转相关页面
    jumpPage(value) {
      this.isNextCheck = false
      const { typeId, fbillNo } = value
      switch (typeId) {
        case 1:
          this.$router.push({ path: `/productionOrder/${fbillNo}` })
          break
        case 2:
          this.$router.push({ path: `/proSuppleDetail/${fbillNo}` })
          break
        case 3:
          this.$router.push({ path: `/proStirageOrder/${fbillNo}` })
          break
      }
      this.isNextCheck = false
    },
    // 保存
    prdbomDetails(ev) {
      const DATA = {
        delArr: this.delArr,
        Entrys: [],
        ftype: 0,
        fbillNo: this.production.fbillNo,
        fprocessCost: this.production.fJcFprice
      }
      this.tableData.forEach(item => {
        DATA.Entrys.push({
          fseq: item.fseq,
          fstockId: item.fstockId,
          isSaled: item.isSaled,
          fissueTypeId: item.fissueTypeId,
          fentryId: item.fentryId,
          fnumeraTor: item.fnumeraTor,
          fissue: item.fissue ? 1 : 0,
          fmaterialId: item.fmaterialId,
          fpaezText: item.fpaezText,
          fneeddate: item.fneeddate
        })
      })
      updatePrdPpbom(DATA).then(res => {
        if (res.code === 0) {
          this.$message({ showClose: true, message: res.message, type: 'success' })
          ev === 1 ? this.submit(1) : this.getSCLLinfo()
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            type: 'error'
          })
        }
      })
    },
    // 获取生产数据
    getSCLLinfo() {
      this.delArr = []
      const id = this.$route.params.id || this.msg
      if (!id) {
        return false
      }
      queryPrdbomDetails({ userNo: id }).then(res => {
        if (res.code === 0) {
          this.production = toMxAmina(res.data)
          this.otherUrlObject = res.data // 操作日志
          this.isDisabled = this.production.fdocumentStatus === this.$t('market.state2') || this.production.fdocumentStatus === this.$t('market.state1')
          // || this.production.fstatusId !== '1'
          this.tableData = res.data.details
          this.fentryData = []
          this.fmoData = []
          this.fmoentryData = []
          this.$nextTick(() => {
            this.tableData.map(item => {
              if (item.isAbleEdit === 1) {
                this.fentryData.push(item.fentryId)
                this.fmoData.push(item.fmoid)
                this.fmoentryData.push(item.fmoentryId)
                this.$refs.multipleTable.toggleRowSelection(item, true)
              } else {
                this.$refs.multipleTable.toggleRowSelection(item, false)
              }
            })
          })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 更新生产订单明细业务状态
    tabStus() {
      const DATA = {
        fentryId: this.production.fmoentryId,
        fstatus: this.production.fstatusId
      }
      updateMoStatus(DATA).then(res => {
        if (res.code === 0) {
          this.getSCLLinfo()
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.getSCLLinfo()
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 触发分子
    handleChange(index) {
      const item = this.tableData[index]
      // 应发数量 = 数量 * 用量
      item.fmustQty = (this.production.fqty * item.fnumeraTor).toFixed(2)
      // 未领数量=应发-已领
      item.fstdQty = maxDecimal(item.fmustQty) - maxDecimal(item.fneedQty)
      if (item.fstdQty < 0) {
        this.$confirm('用量的改变不能使未领数量小于0', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        })
      }
    },
    // 套打
    printing1() {
      const id = this.production.fbillNo
      this.$router.push({
        path: `/proIngredient1/${id}`
      })
    },
    // 多选
    selectData(val) {
      this.delfnumber = val[0]?.fnumber
      this.fentryData = []
      this.fmoData = []
      this.fmoentryData = []
      val.forEach(res => {
        this.fentryData.push(res.fentryId)
        this.fmoData.push(res.fmoid)
        this.fmoentryData.push(res.fmoentryId)
      })
    },
    // 下推弹窗
    pushDown() {
      this.isdanjuDialog = true
    },
    pushDownOrder() {
      if (this.orderLX === this.$t('menu.proPickLian')) {
        const DATA = {
          SoucrceIds: [this.production.fid],
          EntryIds: this.fentryData
        }
        pushToPickmtrl(DATA).then(res => {
          if (res.code === 0) {
            this.$message({ showClose: true, message: res.message, type: 'success' })
            this.$router.push({
              path: `/productionOrder/${res.data.fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.proSupplTong')) {
        const DATA = {
          SoucrceIds: [this.production.fid],
          EntryIds: this.fentryData
        }
        pushToPrdReturnmtrl(DATA).then(res => {
          if (res.code === 0) {
            this.$message({ showClose: true, message: res.message, type: 'success' })
            this.$router.push({
              path: `/proSuppleDetail/${res.data.fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.proStirageOrder')) {
        this.fmoData = Array.from(new Set(this.fmoData))
        this.fmoentryData = Array.from(new Set(this.fmoentryData))
        const DATA = {
          SoucrceIds: this.fmoData,
          EntryIds: this.fmoentryData
        }
        pushToPrdInstock(DATA).then(res => {
          if (res.code === 0) {
            this.$message({ showClose: true, message: res.message, type: 'success' })
            this.$router.push({
              path: `/proStirageOrder/${res.data.fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.proTuiStockDetail')) {
        const DATA = {
          SoucrceIds: this.fmoData,
          EntryIds: this.fmoentryData
        }
        pushToPrdUninstock(DATA).then(res => {
          if (res.code === 0) {
            this.$message({ showClose: true, message: res.message, type: 'success' })
            this.$router.push({
              path: `/proTuiStockDetail/${res.data.fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.supplementary')) {
        const DATA = {
          SoucrceIds: [this.production.fid],
          EntryIds: this.fentryData
        }
        pushToSupplement(DATA).then(res => {
          if (res.code === 0) {
            this.$message({ showClose: true, message: res.message, type: 'success' })
            this.$router.push({
              path: `/supplementaryDetail/${res.data.fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.workFlowOrder')) {
        const DATA = {
          SoucrceIds: this.fmoData,
          EntryIds: this.fmoentryData,
          fbillTypeId: this.fbillTypeId
        }
        insertProcess(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/workFlowDetail/${res.data}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.qualityOrder')) { // 品质
        const DATA = {
          SoucrceIds: [this.production.fmoId],
          EntryIds: [this.production.fmoentryId],
          fbillTypeId: this.fbillTypeId
        }
        pushMoCheck(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/qualityDetail/${res.data}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.outProcessOrder')) { // 外包
        const DATA = {
          SoucrceIds: [this.production.fmoId],
          EntryIds: [this.production.fmoentryId],
          fbillTypeId: this.fbillTypeId
        }
        insertOutsource(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/outProcessDetail/${res.data}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.semifinishDetail')) { // 生产用料单至半成品入库
        const DATA = {
          SoucrceIds: [this.production.fid],
          EntryIds: this.fentryData,
          fbillTypeId: this.fbillTypeId
        }
        insertMoparts(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/semifinishDetail/${res.data}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      }
    },
    // 打开物料弹窗
    materia(index) {
      this.isMateria = true
      this.indexSelf = index
      this.oldFid = this.tableData[index].fentryId
      this.oldfnumber = this.tableData[index].fnumber
    },
    // 获取物料
    materialData(ev) {
      if (ev.fnumber) {
        const item = this.tableData[this.indexSelf]
        item.fmodel = ev.fmodel
        item.fname = ev.fname
        item.fnumber = ev.fnumber
        item.fmaterialId = ev.fmaterialId
        item.fmaterialType = ev.fmaterialType
        item.fspecificaTion = ev.fspecificaTion
        item.fdescripTion = ev.fdescripTion
        item.funitName = ev.fproduceUnit
        item.fproduceUnitId = ev.fproduceUnitId
        item.fissueTypeId = ev.fissuetypeid || item.fissueTypeId
        item.fstockId = ev.fstockId
        item.stockName = ev.fstock
        if (this.oldfnumber !== item.fnumber) {
          item.fentryId = 0
          if (this.oldFid) {
            this.delArr.push(this.oldFid)
          }
          this.oldfnumber = ''
        }
      }
      this.isMateria = false
    },
    // 公共函数
    toExamineFun(api) {
      const DATA = {
        Numbers: [this.production.fbillNo],
        fIds: [this.production.fid],
        EntryIds: this.fentryData
      }
      api(DATA).then(res => {
        if (res.code !== 0) {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
          return
        }
        this.getSCLLinfo()
        this.innerHTM = ''
        res.data.forEach(res => {
          this.innerHTM += '<div>' + res + '</div>'
        })
        this.$notify.warning({
          title: '提示',
          message: this.innerHTM,
          duration: 3000, offset: 50,
          dangerouslyUseHTMLString: true
        })
      })
    },
    // 审批通过
    async audit(ev) {
      const api = ev === 1 ? auditPrdPpboms : unauditPrdPpboms
      this.toExamineFun(api)
    },
    // 提交、反提交
    async submit(ev) {
      const api = ev === 1 ? submitPrdPpboms : unsubmitPrdPpboms
      this.toExamineFun(api)
    },
    settle() {
      const api = finishPrdPpboms
      this.toExamineFun(api)
    },
    check(ev) {
      if (this.fentryData.length === 0) return
      this.cha = ev
      this.upDownVis = true
    },
    // 新增行
    newLine() {
      this.tableData.push({
        fneeddate: new Date(),
        fissueTypeId: 42,
        stockName: '',
        fmodel: '',
        fnumber: '',
        fmaterialId: '',
        fmaterialType: '',
        fspecificaTion: '',
        fdescripTion: '',
        funitName: '',
        fnumeraTor: 1,
        fseq: 0,
        fscrapRate: 0,
        fmustQty: 0,
        fneedQty: 0,
        fstdQty: 0,
        isSaled: 0,
        fpaezText: ''
      })
      this.handleChange(this.tableData.length - 1)
    },
    // 打开仓库弹窗
    handleWarehouse(index) {
      this.indexSelf = index
      this.stockFnumber = this.tableData[index].fnumber
      this.seleceVisiblit = true
    },
    // 获取仓库数据
    selectCK(ev) {
      const item = this.tableData[this.indexSelf]
      if (ev.fstockId) {
        item.fstockId = ev.fstockId
        item.stockName = ev.fname
        item.stockQty = ev.sumQty
      }
      this.seleceVisiblit = false
    },
    // 删除行
    delHang() {
      this.tableData.forEach((res, index) => {
        if (res.fnumber === this.delfnumber) {
          this.delArr.push(res.fentryId)
          this.tableData.splice(index, 1)
          this.$refs.multipleTable.clearSelect()
        }
      })
    },
    handleOther(tab) {
      if (tab.name === 'log') {
        this.$refs.log.otherlog()
      }
    }
  }
}
</script>
<style lang="scss" scope>
.prodeCtionEdit {
  @include listBom;
  .headBtn {
    display: flex;
  }
  .tabPosit {
    padding: 5px;
    box-shadow: 0 0 2px #aaa;
    position: absolute;
    top: 3.5vh;
    left: 0vw;
    background-color: rgba(255, 255, 255, 1);
    z-index: 99999!important;
  }
  .tabPosit1 {
    padding: 5px;
    box-shadow: 0 0 2px #aaa;
    position: absolute;
    top: -25.69vh;
    left:0vw;
    background-color: rgba(255, 255, 255, 1);
    z-index: 9999;
  }
  .el-tabs {
    .el-form {
      display: flex;
      flex-wrap: wrap;
      //height: 160px;
      //overflow: auto;
      .el-input .el-input__inner {
        height: 30px;
        line-height: 30px;
        padding: 0 15px;
      }
      .miaoshu {
        width: 820px !important;
      }
      .el-form-item {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        height: 35px;
        width: 275px;
        margin-bottom: 5px;
        //&::v-deep .el-input__inner{
        //  height: 2.024vh!important;
        //}
        .btnType {
          margin-right: 5px;
        }

        .el-date-editor.el-input {
          width: 100% !important;
        }

        .el-select {
          width: 100%;
        }
      }
    }
  }
  .el-table {
    .el-input-number .el-input__inner {
      padding: 0;
      width: 80px;
    }
    .el-input-number .el-input,
    .el-input-number--mini {
      width: 80px;
    }
    .el-input-number--mini .el-input-number__decrease,
    .el-input-number--mini .el-input-number__increase {
      display: none;
    }
  }
}
</style>
